const ws = new WebSocket("ws://127.0.0.1:8000")// 连接客户端

//上线
ws.onopen = () => {
    ws.send("我上线拉！")
}

// 发送信息 message事件
ws.onmessage = (msg) => {
    console.log(msg);
    const content = document.getElementById("content") //拿到id为content DOM对象
    //用这个DOM对象动态地增加一些数据
    content.innerHTML += msg.data +"<br>"
}

// 报错
ws.onerror = (err) => {
    console.log(err);
}

// 下线
ws.onclose = () => {
    console.log("close");
}